package fr.labri.harmony.analysis.jsep.results.filter;

import java.io.FileOutputStream;
import java.io.IOException;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Set;

import fr.labri.harmony.analysis.jsep.results.Counter;
import fr.labri.harmony.analysis.jsep.results.LoadRules;

public class MigrationDatesCategory extends ResultFilter {

	@Override
	public void computeResult(ResultSet rs) throws SQLException, IOException {
		for(Set<String> libs : LoadRules.getCategories()) {
	
			rs.first();
			Counter c = new Counter();
			while (rs.next()){			
				String source = rs.getString("NAME");
				String target = rs.getString("MIGRATION_LIB_TO");
				if(libs.contains(source) && libs.contains(target)) {
					long datemig = Long.parseLong(rs.getString("TIMESTAMP_OUT"))*1000;
					c.incrDate(source, target,datemig, true);
				}
			}
			c.viewCSVDate(new FileOutputStream("migrations_date_"+libs.toString().substring(0,10)+".csv"));
		}
	}
}
